/**
 * 权限菜单处理模块
 */
(function($ns){
    /**
     * 绑定用户组权限
     */
    $ns.bindGroupResource = function() {
        Qadmin.FW.Ajax.post({
            url: QG_CONFIG.PATH + "bind/bindResource.htm?gid="+ Qadmin.FW.Url.getUrlParam('gid'),
            data: $(':checkbox').serializeArray()
        }, function(){
            Qadmin.FW.Url.goToUrl(QG_CONFIG.PATH + "group/list.htm");
        });
    }
    
    $ns.showAddResource = function(trId) {
        var rand = new Date().getTime(),
            parentId = trId.replace(/node_/g, "");
        var str = '<tr id="dynamic_tab">\n\
                    <td style="padding-left:40px;" class="res_add">\n\
                        <form id="resAddForm_'+ rand +'" style=\"width:900px;\">\n\
                            <input type="hidden" id="parentId" name="parentId" value="'+ parentId +'" />\n\
                            资源名: <input type="text" id="name" name="name" value="" />\n\
			    &nbsp;&nbsp;控制器: <input type="text" id="controller" name="controller" value="" />\n\
                            &nbsp;&nbsp;动作: <input type="text" id="action" name="action" value="" /><br />\n\
			    描&nbsp;&nbsp;&nbsp;述: <input type="text" id="description" name="description" value="" />\n\
                            &nbsp;&nbsp;类型: &nbsp;&nbsp;&nbsp;<select id="type" name="type">\n\
                                    <option value="0">TOP</option>\n\
                                    <option value="1">LEFT</option>\n\
                                    <option value="2">BODY</option>\n\
                                 </select>';
	    str += '&nbsp;&nbsp;权重: <select id="sort" name="sort">';
	    for(var i =0; i<=999; i++) {
		str += '<option value="'+ i +'">'+ i +'</option>'
	    }
	    str += '</select>';
	    str += '&nbsp;&nbsp;<input type="button" class="button_style" value="提交" onclick="Qadmin.App.Resource.addResource('+ rand +');"/>\n\
			    <input type="hidden" name="valiFormId" value="resAddForm_'+ rand +'" />\n\
                        </form>\n\
                    </td>\n\
                </tr>';
	
	var dynamic_tab = $('#dynamic_tab');
	if($(dynamic_tab).size() != 0) {
	    $(dynamic_tab).remove();
	}
        $("#"+ trId).after(str);
    }
    
    $ns.addResource = function(formId) {
        Qadmin.FW.Ajax.post({
            url: QG_CONFIG.PATH + 'resource/add.htm',
            data: $('#resAddForm_'+ formId).serializeArray()
        }, function(xhr){
            location.reload();
        });
    }
    
    $ns.updateResource = function(rid) {
        Qadmin.FW.Url.goToUrl(QG_CONFIG.PATH + "resource/update.htm?rid="+ rid);
    }
    
    $ns.deleteResource = function(rid) {
	Qadmin.FW.Dialog.confirm({
	    msg: '确定要删除记录？',
	    ok: function() {
		Qadmin.FW.Ajax.get({
		    url: [QG_CONFIG.PATH + "resource/delete.htm?rid=", rid].join("")
		}, function(xhr){
		    location.reload();
		});
	    }
	})
    }
})(using("Qadmin.App.Resource"));